package com.ilancuo.tcp;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 根据域名解析IP地址
 * Created by ilancuo on 2019/12/17
 */
public class HostName {
    public static void main(String[] args) {
        try {
            InetAddress address = InetAddress.getByName("www.baidu.com");
            String hostAddress = address.getHostAddress();
            String hostName = address.getHostName();
            System.out.println(hostAddress + "\n" + hostName);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
